rm(list = ls())

forsa <- readRDS("data/forsa.rds")

if (!require("pacman")) install.packages("pacman")
pacman::p_load(dplyr, ggplot2)

# Prepare data for plotting years of autocratic education by birth year

forsa_east <- forsa %>%
  filter(east == 1 & yob < 1999 & yob < 1990) %>%
  mutate(schooling_in_gdr = ifelse(yob < 1972, 0, yob - 1971)) %>%
  filter(!schooling_in_gdr > 12) %>%
  distinct(yob, .keep_all = T) %>%
  dplyr::select(yob, schooling_in_gdr) %>%
  mutate(schooling_in_gdr = 12 - schooling_in_gdr) %>%
  arrange(yob)

# Generate plot

ggplot(forsa_east, aes(yob, schooling_in_gdr)) +
  geom_line() +
  geom_vline(xintercept = 1971, linetype = "dotted") +
  scale_y_continuous(breaks = seq(0, 12, 1)) +
  scale_x_continuous(breaks = c(1955, 1960, 1965, 1970, 1971, 1972, 1975, 1980, 1985, 1990)) +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
  labs(
    y = "Years of education\nunder autocracy",
    x = "Year of birth"
  )
